#include<stdio.h>
#include<stdlib.h>


void jugeUp(int* heap, int childIndex) {
	assert(heap != NULL);
	int child = childIndex;
	int parent = (child - 1) / 2;
	while (child > 0) {
		if (heap[parent] > heap[child]) {
			int temp = heap[parent];
			heap[parent] = heap[child];
			heap[child] = temp;
			child = parent;
			parent = (child - 1) / 2;
		}
		else {
			break;
		}
	}
}

void heapSort(int* arr, int length) {
	for (int i = 0; i < length; i++) {
		jugeUp(arr, i - 1);
	}
}

int main{

	int arr[10] = {4,6,2,5,1};
	int length = sizeof(arr) / sizeof(arr[0]);
	heapSort(arr,length);
	for (int i = 0; i < length; i++) {
		printf("%d ",arr[i]);
	}
	return 0;
}


